#ifndef COMPRESS_CLS
#define COMPRESS_CLS

#include <fstream.h>
#include "const.h"
#include "type.h"

class cpofstream : public ofstream
	{
	public:

		cpofstream(void);
		cpofstream(char *fn);
		~cpofstream();

		cpofstream& operator<< (char c)		{fillbuf(&c,sizeof(char)); return *this;};
		cpofstream& operator<< (short s)		{fillbuf(&s,sizeof(short)); return *this;};
		cpofstream& operator<< (int i)		{fillbuf(&i,sizeof(int)); return *this;};
		cpofstream& operator<< (long l)		{fillbuf(&l,sizeof(long)); return *this;};
		cpofstream& operator<< (float f)		{fillbuf(&f,sizeof(float)); return *this;};
		cpofstream& operator<< (double d)		{fillbuf(&d,sizeof(double)); return *this;};
		cpofstream& operator<< (long double ld)	{fillbuf(&ld,sizeof(long double)); return *this;};
		cpofstream& operator<< (char *s);
		cpofstream& operator<< (void* v);

		cpofstream& put(char c) 						{fillbuf(&c,sizeof(char)); return *this;};
		cpofstream& write(signed char* s, int n)	{fillbuf(s,n); return *this;};
		cpofstream& write(unsigned char* s, int n)	{fillbuf(s,n); return *this;};

		void open(char *fn);
		filebuf* close(void);
		cpofstream& flush(void);

// The following functions are defined so that they are NO OP's:

		cpofstream& seekp(long) {return *this;};
		cpofstream& seekp(long, seek_dir) {return *this;};

// ---

	private:

		void init(void);
		void reset(void);
		void clear(void);
		void encode(void);
		void fillbuf(void* v, int l);
		int compress(uchar *inbuff, uint inbuff_len, uchar *outbuff, uchar *hash_tbl[], uint hash_len);

		uchar *inbuf;				// input buffer
		uchar *outbuf;				// output buffer after compression
		uchar **hash_table;			// hash table
		int idx;					// input buffer index
	};

#endif
